<template>
  <transition
    enter-to-class="animate__animated animate__fadeInUp"
    enter-active-class="animate__animated animate__fadeInUp"
    leave-to-class="animate__animated animate__fadeOutDown"
    leave-active-class="animate__animated animate__fadeOutDown"
  >
    <div class="web-bianqian">
      <div class="btn-box">
        <!-- <button @click="myReturn">«</button> -->
        <span>便签</span>
        <button @click="myEmpty">清空</button>
        <button @click="mySave">保存</button>
      </div>
      <div class="title-box">
        <span>{{ num }} 字</span>
        <input v-model="title" type="text" placeholder="标题" />
      </div>
      <div class="content">
        <textarea
          @input="totalNum"
          v-model="content"
          placeholder="用文字记录"
        ></textarea>
      </div>
      <div class="tip-box" v-if="isEmpty">
        <div class="tip">
          <p>您确定要清空所有内容吗？</p>
          <div class="btn">
            <button @click="yes">确定</button>
            <button @click="no">取消</button>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: "Bianqian",
  data() {
    return {
      num: 0,
      title: "",
      content: "",
      isEmpty: false,
      isOk: 0,
      // obj:{}
    };
  },
  methods: {
    totalNum() {
      this.num = this.content.length;
    },
    myEmpty() {
      if (this.content.length != 0 || this.title.length != 0) {
        this.isEmpty = true;
      } else {
        alert("当前没有需要清空的内容");
      }
    },
    yes() {
      this.isEmpty = false;
      this.title = "";
      this.content = "";
      this.num = 0;
    },
    no() {
      this.isEmpty = false;
    },
    mySave() {
      if (this.title.length == 0 || this.content.length == 0) {
        alert("标题或内容不能为空");
        return false;
      }
      let dt = new Date();
      let yy = dt.getFullYear();
      let mm = dt.getMonth() + 1;
      let dd = dt.getDate();
      mm = mm < 10 ? "0" + mm : mm;
      dd = dd < 10 ? "0" + dd : dd;
      let obj = {};
      obj.title = this.title;
      obj.content = this.content;
      obj.yy = yy;
      obj.mm = mm;
      obj.dd = dd;
      obj.random = (Math.random()).toFixed(5);
      this.$router.push({ path: "/home/topping", query: { obj } });
      //  this.$emit("my-child",obj)
    },
    // myReturn(){
    //   this.$router.go(-1);
    // }
  },
};
</script>

<style lang="less" scoped>
.web-bianqian {
  width: 100%;
  height: 100%;
  background-color: #f0f0f0;
  padding: 0 15px;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1001;
  .btn-box {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    box-sizing: border-box;
    span {
      font-size: 25px;
    }
    button {
      font-size: 25px;

      &:nth-of-type(1) {
        font-size: 16px;
        margin-left: 200px;
      }
      &:nth-of-type(2) {
        font-size: 16px;
      }
    }
  }
  input {
    font-size: 16px;
    background-color: #f0f0f0;
    padding-left: 5px;
    width: 100%;
    margin-bottom: 10px;
  }
  .title-box {
    width: 100%;
    position: relative;
    padding-top: 20px;
    span {
      display: block;
      width: 100px;
      height: 30px;
      font-size: 12px;
      position: absolute;
      right: 5px;
      top: 10px;
      text-align: right;
    }
  }
  .content {
    textarea {
      width: 330px;
      border: 0;
      height: 400px;
      background-color: #f0f0f0;
      font-size: 16px;
      outline: none;
      color: #808080;
      padding-left: 4px;
    }
  }
  .tip-box {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    position: fixed;
    left: 0;
    top: 0;
    .tip {
      width: 300px;
      background-color: #fff;
      position: absolute;
      bottom: 300px;
      left: 40px;
      border-radius: 20px;
      padding: 20px;
      box-sizing: border-box;
      p {
        font-size: 20px;
      }
      .btn {
        width: 100%;
        display: flex;
        justify-content: center;
        margin: 20px 0 0;
        button {
          font-size: 16px;
          border-radius: 10px;
          padding: 2px 10px;
          margin: 0 10px;
        }
      }
    }
  }
}
</style>